(*
  Copyright (c) 2009 Barry Schwartz

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*)

open Box
open Dim
open Environment
open Location
open MathLayout
open UTypes
open XNum
  
type area_contents_arg =
    [
    | `Galley of (uc_string * skip_arg * skip_arg * skip_arg * skip_arg)
    | `Float of (FloatVertical.vert_alignment * skip_arg * skip_arg * dim_arg)
    | `Footnote of
        ((node list) * skip_arg * skip_arg * skip_arg *
           line_param_modifier * par_param_modifier *
           line_break_param_modifier * hyphen_param_modifier *
           space_param_modifier * math_param_modifier)
    | `Direct of (page_info -> (num * num) -> node list)
    ]
and node =
  | Nodes of node list
  | Command of location * env_cmd
  | CommandBox of location * box_cmd
  | GfxCommand of location * (dim_arg, box) Graphic.graphic_command
  | NewGalley of location * uc_string * skip_arg
  | NewLayout of location * uc_string * skip_arg * skip_arg
  | NewArea of location * uc_string * skip_arg * skip_arg * skip_arg
      * skip_arg * skip_arg * skip_arg * area_contents_arg
  | ShipOut of location * uc_string * uc_string * int
  | AddToGalley of location * uc_string * node list
  | PutGalleyInVBox of location * bool * uc_string
  | ModifyGalleyGlue of location
      * (environment -> box list -> box list)
  | Paragraph of location * node list
  | BeginGroup of location
  | EndGroup of location
  | Float of location * uc_string * node list
  | Glyph of location * int * uc_string
  | Letter of location * uc_char
  | WordEnd of location * bool
  | Space of location
  | Glue of location * dim_arg * dim_arg * bool * bool
  | Break of location * num option * bool * node list * node list * node list
  | Rule of location * dim_arg * dim_arg * dim_arg
  | Image of location * string * skip_arg * skip_arg
  | Accent of location * uc_char * node list
  | HBox of location * [ | `LR | `RL | `Default ] * node list
  | HBoxTo of location * [ | `LR | `RL | `Default ] * skip_arg * node list
  | HBoxSpread of location * [ | `LR | `RL | `Default ] * skip_arg * node list
  | VBox of location * node list
  | VBoxTo of location * skip_arg * node list
  | VBoxSpread of location * skip_arg * node list
  | Phantom of location * bool * bool * node list
  | HLeaders of location * dim_arg * node list
  | VInsert of location * bool * node list
  | PositionBox of location
      * (environment -> dim -> dim -> dim -> (num * num))
      * node list
  | Table of location * node list
  | TableEntry of location * int * int * int * int * int * node list
  | Math of location * node list
  | MathCode of location * math_code * node list
  | MathChar of location
      * (math_code * (int * int) * (uc_char * uc_char))
  | SubScript of location * node list
  | SuperScript of location * node list
  | Fraction of location * node list * node list * node * node
      * skip_arg
  | Underline of location * node list
  | Overline of location * node list
  | MathAccent of location * int * uc_char * node list
  | Root of location * int * uc_char * int * uc_char * node list
  | LeftRight of location * (node list) list
  | MathStyle of location * math_style
  | IndexPosition of location * Box.index_position

(* with sexp_of *)
